<template>
	<div>
		<div v-show="!imgShow">
			<images-upload @getChild='parentFn' :childData='childData'></images-upload>
			<div class="demos-content-padded" style="padding: 0.3rem 1.1rem;">
				<a href="javascript:;" class="weui-btn weui-btn_primary" @click='confirmClick'>
					{{!Imgs?'确定':'重新上传'}}
				</a>
			</div>
		</div>
		<div class="imgWarp" v-show="imgShow">
			<img v-for="(item,index) in Imgs" :key=index :src="imgBaseUrl+item">
		</div>
	</div>
</template>

<script>
	import imgUpload from '../../components/common/singleUpload'
	import {
		getStore
	} from '../../config/mUtils'
	import {
		getSignContract,
		uploadClientSignContract
	} from '../../config/api'
	import {
		imgBaseUrl
	} from '../../config/axios'
	import {
		Toast,
		TopTips
	} from 'we-vue'
	export default {
		inject: ['reload'],
		data() {
			return {
				formData: '',
				orderNo: this.$route.query.orderNo,
				status: this.$route.query.status,
				imgShow: true,
				Imgs: [],
				imgBaseUrl:imgBaseUrl,
				childData: {
					fileName: 'file',
					singleUpload: true,
					multiple:true
				}
			}
		},
		mounted() {
			getSignContract(getStore('clientId'), this.orderNo).then(res => {
				console.log(res)
				if (this.status == 1) {
					this.imgShow = this.imgShow
					if(res.code == 100){
						if(!res.content.pdfUrl){
							this.Imgs = res.content.picList
						}else{
							window.location.href = imgBaseUrl + res.content.pdfUrl
						}
					}else{
						TopTips("暂无数据!")
					}
				} else {
					if(!res.content.pdfUrl){
						this.imgShow = !this.imgShow
					}
				}
			}).catch(err => {})
		},
		methods: {
			parentFn(data) {
				this.formData = data
			},
			confirmClick() {
				if (!this.formData) {
					TopTips({
						message:'请先选择图片',
						duration:1200
					})
				} else {
					this.formData.append('orderNo', this.orderNo)
					uploadClientSignContract(this.formData).then((res) => {
						if (res.code == 100) {
							Toast.success('上传成功');
							setTimeout(() => {
								this.reload()
							}, 1200)
						}
					}).catch(res => console.log(res))
				}
			}
		},
		components: {
			'images-upload': imgUpload
		},
	}
</script>

<style scoped="scoped" lang="less">
	.imgWarp {
		img {
			width: 100%;
			height: auto
		}
	}
</style>
